<template>
  <div id="box">
    <el-row>
      <el-col :span="22" :push="1">
        <div class="grid-content bg-purple" style="height: 77px">
          <span style="line-height: 77px; font-size: 14px"> </span>
          <span style="margin-left: 20px">
            <el-button type="primary" @click="skip">添加角色</el-button>
          </span>
        </div>
      </el-col>
    </el-row>
    <!-- 搜索栏start -->
    <el-row>
      <el-col :span="22" :push="1">
        <div class="grid-content bg-purple" style="height: 77px">
          <span style="line-height: 77px; font-size: 14px; margin-left: 20px">
            关键词
            <el-input
              v-model="form.name"
              size="small"
              placeholder="请输入角色名称"
              style="width: 150px"
            ></el-input>
          </span>
          <span style="margin-left: 20px">
            <el-button type="primary" @click="search()">搜索</el-button>
            <el-button @click="reset()">重置</el-button>
          </span>
        </div>
      </el-col>
    </el-row>
    <!-- 搜索栏end -->
    <!-- 表格 -->
    <el-row>
      <el-col :span="22" :push="1">
        <div class="grid-content bg-purple">
          <span style="padding-left: 10px">
            <el-table
              :data="tableData"
              border
              style="width: 96.5%; margin-left: 20px"
            >
              <el-table-column prop="id" label="角色编号" width="120">
              </el-table-column>
              <el-table-column prop="name" label="角色名称" width="230">
              </el-table-column>
              <el-table-column prop="roleDescribe" label="角色描述" width="510">
              </el-table-column>
              <el-table-column prop="userRoleCount" label="员工数" width="140">
              </el-table-column>
              <el-table-column label="操作" width="140">
                <template slot-scope="scope">
                  <el-button
                    @click="handleClick(scope.row)"
                    type="text"
                    size="small"
                    >删除</el-button
                  >
                  <el-button
                    @click="handleClick(scope.row)"
                    type="text"
                    size="small"
                    >修改</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <div class="grid-content bg-purple-dark">
              <div class="block">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="pageNum"
                  :page-sizes="[5, 10, 20, 50]"
                  :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total"
                >
                </el-pagination>
              </div>
            </div>
          </span>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
  
  <script>
import axios from "axios";
export default {
  data() {
    return {
      form: {},
      pageNum:1,
      pageSize:5,
      total: 1,
      tableData: [],
    };
  },
  created() {
    this.getRole()
  },
  methods: {
    reset() {
      this.form = {};
    },
    search(){
      this.getRole()
    },
    // 获取角色信息
    getRole() {
      axios
        .post("/role/queryAllRoles?pageSize="+this.pageSize+"&pageNum="+this.pageNum, this.form)
        .then((res) => {
          console.log(res);
          this.total = res.data.data.total
          this.tableData = res.data.data.records
        });
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      this.pageSize = val;
      this.getRole();
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getRole();
    },
    skip(){
      this.$router.push("/AddAndUpRole")
    }
  },
};
</script>
  
  <style scoped>
/* element-ui样式 */
.el-row {
  margin-bottom: 10px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple {
  background: #fff;
  border-radius: 10px;
}

/* 自定义样式 */
/* * {
    margin: 0px;
    padding: 0px;
  } */
.box {
  width: 98%;
  height: 100%;
  margin: auto;
  /* background-color: red; */
}
.block {
  padding-top: 20px;
  padding-left: 700px;
}
</style>